<?php

namespace app\api\controller\yalimedia;

use app\common\controller\Api;

/**
 * 教师接口
 */
class Teacher extends Api
{
    // 无需登录的接口,*表示全部
    protected $noNeedLogin = [];
    // 无需鉴权的接口,*表示全部
    protected $noNeedRight = ['*'];

    /**
     * 获取名师列表
     * @throws \think\Exception
     */
    public function index()
    {
        $page = $this->request->post('page');
        $limit = $this->request->post('limit');

        $teacher = new \addons\yalimedia\service\Teacher();
        $where = ['is_master'=>1];
        $data = $teacher->getTeacherList($where,$page,$limit);
        foreach($data['data'] as &$v){
            $v['image'] = $this->request->domain().$v['image'];
            $v['course_num'] = $teacher->getCourseNum($v['id']);
            $v['study_num'] = $teacher->getStudyNum($v['id']);
        }
        $this->success('请求成功', $data);
    }


    /**
     * 获取推荐名师列表
     * @throws \think\Exception
     */
    public function hot()
    {
        $page = $this->request->post('page');
        $limit = $this->request->post('limit');

        $teacher = new \addons\yalimedia\service\Teacher();
        $where = ['is_hot'=>1,'is_master'=>1];
        $data = $teacher->getTeacherList($where,$page,$limit);
        foreach($data['data'] as &$v){
            $v['image'] = $this->request->domain().$v['image'];
        }
        $this->success('请求成功', $data);
    }

    /**
     * 名师详情
     */
    public function info(){
        $id = $this->request->post('id');
        $teacher = new \addons\yalimedia\service\Teacher();
        $where = ['id'=>$id,'is_master'=>1];
        $data = $teacher->getTeacherInfo($where);
        $data['course_num'] = $teacher->getCourseNum($id);
        $data['study_num'] = $teacher->getStudyNum($id);
        $this->success('请求成功', $data);
    }

    /**
     * 获取教师课程列表
     * @throws \think\Exception
     */
    public function course_list()
    {
        $tid = $this->request->post('tid');
        $page = $this->request->post('page');
        $limit = $this->request->post('limit');

        $subject = new \addons\yalimedia\service\Course();
        $data = $subject->getCourseList(['teacher_id'=>$tid],$page,$limit);
        foreach($data['data'] as &$v){
            $v['cover'] = $this->request->domain().$v['cover'];
        }
        $this->success('请求成功', $data);
    }


}
